package tkM

import (
	"fmt"
	"db2s/outPut"
	"strings"
	"sync/atomic"
)

func taskNameIndex(t string) (s string) {
	switch t {
	case "P":
		s = "Primary"
	case "U":
		s = "Unique"
	case "I":
		s = "Index"
	default:
		s = "MissIndex"
	}
	return
}
func taskNameType(p outPut.Task) (s string) {

	switch {
	case len(p.TextCT) > 0 && strings.Contains(strings.ToLower(p.TextCT), "lob"):
		s = "Lob"
		return
	case len(p.TextCT) > 0 && strings.Contains(strings.ToLower(p.TextCT), "varchar"):
		s = "Text"
		return
	default:
		s = "Normal"
	}
	return
}
func taskNameCount(sum int64) (s string) {
	var (
		baseUnit int64 = 10000
	)
	switch {
	case sum < 10*baseUnit:
		s = "10w"
	case sum < 100*baseUnit:
		s = "100w"
	case sum < 1000*baseUnit:
		s = "1000w"
	case sum < 10000*baseUnit:
		s = "1y"
	case sum < 100000*baseUnit:
		s = "10y"
	default:
		s = "100y"
	}
	return
}
func taskNameGenerate(subMode string, plan *SchedulePlan2) (s string) {
	var (
		indexType string
		sum       string
		textType  string
	)
	switch subMode {
	case "sync", "rows":
		indexType = taskNameIndex(plan.TPod.IndexType)
		sum = taskNameCount(atomic.LoadInt64(plan.TPod.Task.Sum))
		textType = taskNameType(plan.TPod.Task)
		plan.TPod.Options = fmt.Sprintf("%v_%v_%v", indexType, sum, textType)
		return fmt.Sprintf("%v/%v_%v_%v", plan.Object.Role, indexType, sum, textType)
	case "struct":
		if plan.TableTargetStatus {
			return fmt.Sprintf("%v/%v", plan.Object.Role, "Alter")
		}
		return fmt.Sprintf("%v/%v", plan.Object.Role, "Create")
	case "object":
		if plan.TableTargetStatus {
			return fmt.Sprintf("%v/%v", plan.Object.Role, "Alter")
		}
		return fmt.Sprintf("%v/%v", plan.Object.Role, "Create")
	default:
		return
	}
}
